package com.example.newsapp.ui.navigation

import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.example.newsapp.data.compositionLocal.LocalNavControllerTab
import com.example.newsapp.data.`object`.StateSave
import com.example.newsapp.data.`object`.TabNavigation
import com.example.newsapp.ui.components.newsComponent.newsList.CarNewsList
import com.example.newsapp.ui.components.newsComponent.newsList.HeadNewsList
import com.example.newsapp.ui.components.newsComponent.newsList.HotNewsList
import com.example.newsapp.ui.components.newsComponent.newsList.InternationNewsList
import com.example.newsapp.ui.components.newsComponent.newsList.JokeNewsList
import com.example.newsapp.ui.components.newsComponent.newsList.NBANewsList
import com.example.newsapp.ui.components.newsComponent.newsList.SuggestNewsList

/**
 * 新闻标签导航
 */
@Composable
fun TabNavigation(modifier: Modifier = Modifier, ) {
    var navControllerTab = LocalNavControllerTab.current
    // 新闻标签导航图
    NavHost(
        navController = navControllerTab,
        startDestination = TabNavigation.suggestTab
    ) {
        // 推荐页新闻列表
        composable(
            route = TabNavigation.suggestTab,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { -it }
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { -it }
                )
            }
        ) {
            SuggestNewsList()
        }
        // 热点新闻列表
        composable(
            route = TabNavigation.hotTab,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (StateSave.previousTab < 1) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (StateSave.currentTab < 1) it else -it}
                )
            }
        ) {
            HotNewsList()
        }
        // 头条新闻列表
        composable(
            route = TabNavigation.headTab,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (StateSave.previousTab < 2) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (StateSave.currentTab < 2) it else -it}
                )
            }
        ) {
            HeadNewsList()
        }
        // NBA新闻列表
        composable(
            route = TabNavigation.NBATab,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (StateSave.previousTab < 3) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (StateSave.currentTab < 3) it else -it}
                )
            }
        ) {
            NBANewsList()
        }
        // 汽车新闻列表
        composable(
            route = TabNavigation.carTab,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (StateSave.previousTab < 4) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (StateSave.currentTab < 4) it else -it}
                )
            }
        ) {
            CarNewsList()
        }
        // 笑话新闻列表
        composable(
            route = TabNavigation.jokeTab,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (StateSave.previousTab < 5) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (StateSave.currentTab < 5) it else -it}
                )
            }
        ) {
            JokeNewsList()
        }
        // 国际新闻列表
        composable(
            route = TabNavigation.internationTab,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (StateSave.previousTab < 6) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (StateSave.currentTab < 6) it else -it}
                )
            }
        ) {
            InternationNewsList()
        }
    }
}